package com.lsz.crm.controller;

import com.lsz.crm.base.BaseController;
import com.lsz.crm.base.ResultInfo;
import com.lsz.crm.enums.StateStatus;
import com.lsz.crm.pojo.CusDevPlan;
import com.lsz.crm.pojo.SaleChance;
import com.lsz.crm.query.CusDevPlanQuery;
import com.lsz.crm.query.SaleChanceQuery;
import com.lsz.crm.service.CusDevPlanService;
import com.lsz.crm.service.SaleChanceService;
import com.lsz.crm.utils.LoginUserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @Author liushizhong
 * @Date 2021/10/12 15:53
 * @Version 1.0
 */

@RequestMapping("cus_dev_plan")
@Controller
public class CusDevPlanController extends BaseController {

    @Autowired
    private SaleChanceService saleChanceService;

    @Autowired
    private CusDevPlanService cusDevPlanService;

    @RequestMapping("index")
    public String index(){

        return "cusDevPlan/cusDevPlan";
    }

    @RequestMapping("toCusDevPlanPage")
    public String toCusDevPlanPage(Integer id,HttpServletRequest request){
        // 调用service,通过id查询营销机会
        SaleChance saleChance = saleChanceService.selectByPrimaryKey(id);
        // 将对象设置到请求域
        request.setAttribute("saleChance",saleChance);
        return "cusDevPlan/cusDevPlanData";
    }

    /**
     * 客户开发计划数据查询
     * @param cusDevPlanQuery
     * @return
     */
    @RequestMapping("list")
    @ResponseBody
    public Map<String,Object> queryCusDevPlanByParams(CusDevPlanQuery cusDevPlanQuery){
        // 调用 service 查询客户开发计划
        return cusDevPlanService.queryCusDevPlanByParams(cusDevPlanQuery);
    }

    @ResponseBody
    @RequestMapping("add")
    public ResultInfo addCusDevPlan(CusDevPlan cusDevPlan){
        cusDevPlanService.addCusDevPlan(cusDevPlan);
        return success("计划项添加成功！");
    }

    @ResponseBody
    @RequestMapping("update")
    public ResultInfo updateCusDevPlan(CusDevPlan cusDevPlan){
        cusDevPlanService.updateCusDevPlan(cusDevPlan);
        return success("计划项更新成功！");
    }

    @ResponseBody
    @RequestMapping("del")
    public ResultInfo delCusDevPlan(Integer id){
        cusDevPlanService.delCusDevPlan(id);
        return success("计划项删除成功！");
    }

    /**
     * 更新营销机会的开发状态
     * @param id
     * @param devResult
     * @return
     */
    @ResponseBody
    @RequestMapping("updateSaleChanceDevResult")
    public ResultInfo updateSaleChanceDevResult(Integer id,Integer devResult){
        saleChanceService.updateSaleChanceDevResult(id,devResult);
        return success("营销机会开发状态修改成功！");
    }



    @RequestMapping("toAddAndUpdatePage")
    public String toAddAndUpdatePage(Integer saleChanceId,Integer id,HttpServletRequest request){
        // 将营销机会的 id 设置到请求域中
        request.setAttribute("saleChanceId",saleChanceId);

        // 通过计划项 id 查询记录
        CusDevPlan cusDevPlan = cusDevPlanService.selectByPrimaryKey(id);
        // 设置到请求域中
        request.setAttribute("cusDevPlan",cusDevPlan);
        return "cusDevPlan/addAndUpdate";
    }
}
